//
//  NavigationController.m
//  rssreader
//
//  Created by Zzz on 15/11/29.
//  Copyright © 2015年 Zzz. All rights reserved.
//

#import "BaseNav.h"
#import "LineView.h"
#import "UIView+UIView_ITAdditions.h"

@interface BaseNav ()

@end

@implementation BaseNav

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationBar.translucent = NO;
//    self.navigationBar.barTintColor = [UIColor blueColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

@end

#define kNavBarBtnTitleColor ([UIColor blackColor])
@implementation BaseNavBar : UIView
{
    UIImageView * _mpBgImageView;
    UILabel     * _mpNavLabel;
    UIButton    * _mpLeftBtn;
    UIButton    * _mpRightBtn;
    LineView    * _mpLineView;
}
+ (BaseNavBar *)create
{
    BaseNavBar * navBar = [[BaseNavBar alloc]init];
    
    return navBar;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI
{
    [self setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    [self setBackgroundColor:[UIColor whiteColor]];
    CGSize btnSize = CGSizeMake([self getFrame_height]-20, [self getFrame_height]-20);

    _mpLeftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage * backImage = [UIImage imageNamed:@"BackButtonBlue.png"];
    [_mpLeftBtn setBackgroundImage:backImage forState:UIControlStateNormal];
    [self addSubview:_mpLeftBtn];
    [_mpLeftBtn setFrame:CGRectMake(0, 20, btnSize.width, btnSize.height)];
    
    _mpNavLabel = [[UILabel alloc]init];
    [_mpNavLabel setFont:[UIFont systemFontOfSize:18]];
    [_mpNavLabel setTextColor:[UIColor blackColor]];
    [_mpNavLabel setTextAlignment:NSTextAlignmentCenter];
    [_mpNavLabel setText:@""];
    [self addSubview:_mpNavLabel];

    [_mpNavLabel setFrame:CGRectMake(0, 20, SCREEN_WIDTH - btnSize.width * 2, btnSize.height)];
    [_mpNavLabel setCenterX:SCREEN_WIDTH/2];
}
#pragma mark - **************** getter
- (UIButton *)getLeftBtn
{
    return _mpLeftBtn;
}
- (UIButton *)getRightBtn
{
    return _mpRightBtn;
}

- (UILabel *)getTitleLable
{
    return _mpNavLabel;
}
- (UIColor *)getNavColor
{
    return self.backgroundColor;
}
#pragma mark - **************** setter
- (void)setTitle:(NSString *)navTitle
{
    [_mpNavLabel setText:navTitle];
}

- (void)setLeftBtn:(NAV_BAR_LEFT_BTN_TYPE)btnType
{
    NSString * imageName = @"";
    switch (btnType) {
        case NAV_BAR_LEFT_BTN_TYPE_BLUE:
            imageName = @"BackButtonBlue.png";
            [_mpNavLabel setTextColor:[UIColor blackColor]];
            break;
        case NAV_BAR_LEFT_BTN_TYPE_WHITE:
            imageName = @"BackButtonWhite.png";
            [_mpNavLabel setTextColor:[UIColor whiteColor]];
            break;
        default:
            break;
    }
    [_mpLeftBtn setBackgroundImage:nil forState:UIControlStateNormal];
    [_mpLeftBtn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
}
- (void)setNavBackColor:(UIColor *)color
{
    [self setBackgroundColor:color];
}

- (void)setHideLeftBtn:(BOOL)isHide
{
    [_mpLeftBtn setHidden:isHide];
}

- (void)setRightView:(UIView *)view
{
    [_mpRightBtn setHidden:YES];
    [self addSubview:view];
    [view setFrame_y:20];
    [view setFrame_x:SCREEN_WIDTH - [view getFrame_width]];
}
@end